<template>
	<view>
		<web-view :src="url"></web-view>

		<!-- 隐私政策确认按钮 - 只在隐私政策页面显示 -->
		<view v-if="isPrivacyPolicy" class="privacy-confirm-bar">
			<button class="btn-agree" @click="agreePrivacyPolicy">已阅读，同意并继续</button>
			<button class="btn-cancel" @click="cancelPrivacyPolicy">暂不使用</button>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			url: '',
			isPrivacyPolicy: false,
			version: '1.0.0'
		};
	},
	onLoad(options) {
		// 获取传递的URL参数
		if (options.url) {
			this.url = decodeURIComponent(options.url);
			console.log('webview加载URL:', this.url);

			// 检查是否是隐私政策页面
			this.isPrivacyPolicy = this.url.includes('service.html');
		} else {
			uni.showToast({
				title: '链接无效',
				icon: 'none'
			});
			setTimeout(() => {
				uni.navigateBack();
			}, 1500);
		}

		// 获取版本号
		if (options.version) {
			this.version = options.version;
		}

		// 设置导航栏标题
		if (options.title) {
			uni.setNavigationBarTitle({
				title: decodeURIComponent(options.title)
			});
		} else {
			uni.setNavigationBarTitle({
				title: '客服中心'
			});
		}
	},
	methods: {
		// 同意隐私政策
		agreePrivacyPolicy() {
			// 保存同意记录
			uni.setStorageSync('privacy_policy_agreed', true);
			uni.setStorageSync('privacy_policy_version', this.version);
			uni.setStorageSync('privacy_policy_agreed_time', new Date().toISOString());

			uni.showToast({
				title: '感谢您的同意',
				icon: 'success'
			});

			// 返回应用
			setTimeout(() => {
				uni.navigateBack();
			}, 1500);
		},

		// 取消隐私政策
		cancelPrivacyPolicy() {
			uni.showModal({
				title: '提示',
				content: '您需要同意隐私政策才能使用本应用',
				confirmText: '重新考虑',
				cancelText: '退出应用',
				success: (res) => {
					if (res.confirm) {
						// 用户选择重新考虑，继续停留在页面
					} else if (res.cancel) {
						// 退出应用
						// #ifdef APP-PLUS
						plus.runtime.quit();
						// #endif
					}
				}
			});
		}
	}
};
</script>

<style>
.privacy-confirm-bar {
	position: fixed;
	bottom: 0;
	left: 0;
	right: 0;
	background: #fff;
	padding: 20rpx 30rpx;
	box-shadow: 0 -2rpx 10rpx rgba(0, 0, 0, 0.1);
	display: flex;
	gap: 20rpx;
	z-index: 9999;
}

.btn-agree,
.btn-cancel {
	flex: 1;
	height: 80rpx;
	line-height: 80rpx;
	text-align: center;
	border-radius: 8rpx;
	border: none;
	font-size: 28rpx;
}

.btn-agree {
	background: #2FC971;
	color: #fff;
}

.btn-cancel {
	background: #f5f5f5;
	color: #666;
}
</style>

<style>
</style>